
const JWT = require('jsonwebtoken')
let secretOrPrivateKey = 'adflkjafdlkjad;lfkjsa;dfkjsf我是锁子'
//生成token
function getToken( data,expiresIn = 3600 ){ //1*60*60
   return JWT.sign( data,secretOrPrivateKey,{expiresIn} )
}

//const getToken = (data,expiresIn = 3600)=>JWT.sign( data,secretOrPrivateKey,{expiresIn} )


//验证token
function verifyToken( token ){
    
    try {
      return  JWT.verify( token,secretOrPrivateKey )
    } catch (error) {
        return false
    }
}


//demo
let data = {
    mid:'xxx-0001-xxx',
    tel:'15811112222',
    username:'zs'
}

// let tokenStr = getToken( data )
// console.log( tokenStr,'aaa' )

// let t = 'asdfeyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtaWQiOiJ4eHgtMDAwMS14eHgiLCJ0ZWwiOiIxNTgxMTExMjIyMiIsInVzZXJuYW1lIjoienMiLCJpYXQiOjE2NDE4ODM1NjksImV4cCI6MTY0MTg4NzE2OX0.oXMe6Mb4krYlwTNdndxyu-bN0xMPyQXzEnYWE_9dhEE'

// let isLogin = verifyToken( t )
// console.log( isLogin )//如果是对象代表真，代表登录了